import java.io.File;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Main {
    public static final int NEW_WIDTH = 300;

    public static void main(String[] args) {
        String srcFolder = "data/src";
        String dstFolder = "data/dst";

        File srcDir = new File(srcFolder);
        new File(dstFolder).mkdirs();

        List<File> files = new CopyOnWriteArrayList<>(srcDir.listFiles());

        ArrayList<ImageResizerThread> threads = new ArrayList<>();

        for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
            threads.add(new ImageResizerThread(files, dstFolder, NEW_WIDTH));
        }

        long start = System.currentTimeMillis();

        threads.forEach(Thread::start);
        threads.forEach((t) -> {
            try {
                t.join();
            } catch (InterruptedException ignored) {}
        });

        System.out.println("Duration: " + (System.currentTimeMillis() - start));
    }
}
